package com.yxp.offer;

/**
 * @author : yang.xp
 * @date : 2021/9/1 18:47
 * @description : 剑指 Offer 16. 数值的整数次方
 */
public class Problem16 {

    public static void main(String[] args) {
        Problem16 problem16 = new Problem16();
        double v = problem16.myPow(2, 6);
        System.out.println(v );
    }

    public double myPow(double x, int n) {
        if (x == 0) return 0;
        long b = n;
        double res = 1.0;
        if (b < 0) {
            x = 1 / x;
            b = -b;
        }
        while (b > 0) {
            if ((b & 1) == 1) res *= x;
            x *= x;
            b >>= 1;
        }
        return res;
    }
}
